package org.aileen.springmvc.Controller;


import jakarta.servlet.http.HttpServletResponse;
import org.aileen.springmvc.model.UserInfo;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@RequestMapping("/response")
//@RestController
@Controller
public class ResponseController {
    //返回视图
    @ResponseBody//加上后视图变成数据
    @RequestMapping("/index")
    public String index() {
        return "/index.html";
    }

    //返回数据
    //@ResponseBody
    @RequestMapping("/returnData")
    public String returnData(){
        return "返回数据";
    }

    //返回HTML代码
    @ResponseBody
    @RequestMapping("/returnHTMLcode")
    public String returnHTMLcode(){
        return "<h1>Hello Aileen<h1>";
    }

    //返回JSON数据
    @ResponseBody
    @RequestMapping("/returnJson")
    public UserInfo returnJson(){
        UserInfo userInfo = new UserInfo("Aileen" , "6666" ,  22);
        return userInfo;
    }

    //设置响应状态码
    @ResponseBody
    @RequestMapping("/setStatus")
    public String setStatus(HttpServletResponse response){
        response.setStatus(401);
        return "设置状态码成功";
    }

    //设置Content-Type类型
    @ResponseBody
    @RequestMapping(value = "r1",produces = "application/json; charset = UTF-8")
    public String r1(){
        return "{\"status\":400}";
    }

    //设置Header
    @ResponseBody
    @RequestMapping("/setHeader")
    public String setHeader(HttpServletResponse response){
        response.setHeader("MyHeader" , "MyHeaderValue");
        return "Aileen's Header";
    }



}
